#include "Game.h"

Game::Game()
{
	m_background = *new Picture();

	// Objects
	pPlayer = new Player();
}

bool Game::Init(char* host)
{
	m_window.Create(sf::VideoMode(800, 600), "Revenge of the Puppy Armageddon", 
		sf::Style::Close, sf::WindowSettings(24, 8, 16));

	m_window.SetFramerateLimit(60);

	m_background.LoadFromFile("Content/Textures/System/Background.png");

	// Init objects
	// Player
	pPlayer->Init();
	pPlayer->base.sprite.SetPosition(200, 400);

	// Set the game state to RUNNING
	m_state = S_RUNNING;
	return true;
}

void Game::Loop()
{
	/// This will update n shit
	m_window.GetEvent(m_event);
	
	if (m_event.Type == sf::Event::Closed)
		m_state = S_USEREXIT;

	// World
	std::vector<sf::Rect<int>> world;
	world.clear();

	// Update local player
	pPlayer->Update(&m_window, world);

	m_window.Clear(sf::Color(100, 149, 237));

	// Draw the background
	m_background.Draw(&m_window);

	// Render objects
	pPlayer->Render(&m_window);

	// Calculate and show fps
	std::ostringstream buff;
	buff << floorf(1.f / m_window.GetFrameTime());

	sf::String fps_string(buff.str(), sf::Font::GetDefaultFont(), 16);
	fps_string.SetPosition(5, 1);
	fps_string.SetColor(sf::Color(0, 0, 225));

	m_window.Draw(fps_string);

	m_window.Display();
}

void Game::Exit()
{

}